/**
 * Created by elead on 2018/11/1.
 */
function getQueryStringByNameTwo(name){
    var url = location.href;
    var search0 =  url.split("?")[0];
    var search = "?" + url.split("?")[1];
    var result0 = search0.match(new RegExp("[\?\&\?]" + name + "=([^\&]+)", "i"));
    var result = search.match(new RegExp("[\?\&\?]" + name + "=([^\&]+)", "i"));
    if(result &&  result.length > 1){
        return result[1];
    }else if(result0 &&  result0.length > 1){
        return result0[1];
    } else{
        return "";
    }
}
function maximizeWindow(){//页面打开窗口大小为屏幕尺寸大小；
    var offset = (getIndexof(navigator.userAgent,"Mac") != -1 || getIndexof(navigator.userAgent,"Gecko") != -1 ||
    getIndexof(navigator.appName,"Netscape") != -1) ? 0 : 4;
    window.moveTo(-offset, -offset);
    window.resizeTo((screen.availWidth + (2 * offset))*(1), (screen.availHeight + (2 * offset))*(0.8));
}
function IEVersion() {
    var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
    var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器
    var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器
    var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
    if(isIE) {
        var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
        reIE.test(userAgent);
        var fIEVersion = parseFloat(RegExp["$1"]);
        if(fIEVersion == 7) {
            return 7;
        } else if(fIEVersion == 8) {
            return 8;
        } else if(fIEVersion == 9) {
            return 9;
        } else if(fIEVersion == 10) {
            return 10;
        } else {
            return 6;//IE版本<=7
        }
    } else if(isEdge) {
        return 'edge';//edge
    } else if(isIE11) {
        return 11; //IE11
    }else{
        return -1;//不是ie浏览器
    }
}

function getUrlParam(url){//获取公用参数
    if(!url)  return false;
        //params.commonParams[v]
        var regX = /\?/g;
        var urlArr=[];
        url=url.split("?")[1]
        if(regX.test(url)){
            url=url.split("?")[1]
            if(url.indexOf()){
                urlArr=url.split("&");
            }else{
                urlArr.push(url);
            }
        }
    return url;
}
function splitMes(str){
    var ss="";
    var arMes=""
    if(str.indexOf("(")>0){
        ss="("
    }else if(str.indexOf("（")>0){
        ss="（"
    }
    if(ss!=""){
        arMes=str.split(ss)[0];
    }else{
        arMes=str;
    }
    return arMes;
}
function impacSplit(str){
    var ss="";
    var bb="";
    var eData={};
    if(str.indexOf("(")>0){
        ss="("
    }else if(str.indexOf("（")>0){
        ss="（"
    }
    if(str.indexOf(")")>0){
        bb=")"
    }else if(str.indexOf("）")>0){
        bb="）"
    }
    if(ss!=""&&bb!=""){
        var arr=str.split(ss);
        var arr1=str.split(ss)[1].split(bb)[0];
        if(str.split(ss)[1].split(bb)[1]!=""){
            eData.effectnumber="";
            eData.view="";
        }else{
            eData.effectnumber=arr[0];
            eData.view=arr1;
        }

    }else{
        eData.effectnumber="";
        eData.view="";
    }

    return eData;

}
//获取系统当前日期
function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var seperator2 = ":";
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
        + " " + date.getHours() + seperator2 + date.getMinutes()
        + seperator2 + date.getSeconds();
    return currentdate;
}

//时间分割
function splitDataTime(params){
    var timeArr1=params.split("-");
    var time1="";
    for(var v1 in timeArr1){
        if(timeArr1[v1].length>1){
            time1=time1+""+timeArr1[v1];
        }else{
            time1=time1+"0"+timeArr1[v1];
        }

    }
    return time1;
}


//创建提示弹框
function tost(nodeText){
    //先清除tost弹框；
    try {
        document.body.removeChild(document.querySelector('div.tost'));
    } catch (e) {

    }
    //创建tost弹框；
    var DIV = document.createElement("div");
    DIV.appendChild(document.createTextNode(nodeText));
    var DIVclass = DIV.classList.add("tost");
    document.body.appendChild(DIV);
    var time = setTimeout(function(){

        document.body.removeChild(document.querySelector('div.tost'));
        clearTimeout(time)
    },1500)
}

//创建弹框

function createDiglog(nodeText,callback){
    try {
        document.body.removeChild(document.querySelector('div.diglog'));
    } catch (e) {

    }
   if(callback==""||callback==undefined){
       var g="<div class='diglog'><i class='iconfont closeDig'>&#xe6a4;</i><div class='diglogBox'><div class='diglogHeader'><i class='iconfont'>&#xe73d;</i></div><div class='nodeText'>"+nodeText+"</div>";
       g+="<div class='makeSure'>确定</div></div>";
   }else{
       var g="<div class='diglog'><i class='iconfont successDig'>&#xe648;</i><div class='diglogBox'><div class='diglogHeader'><i class='iconfont'>&#xe73d;</i></div><div class='nodeText'>"+nodeText+"</div>";
       g+="<div class='makeSure'>确定</div></div>";
   }
    $("body").append(g);

    $(".closeDig").click(function(){
        try {
            document.body.removeChild(document.querySelector('div.diglog'));
        } catch (e) {

        }
        callback()
    })
    $(".makeSure").click(function(){
        try {
            document.body.removeChild(document.querySelector('div.diglog'));
        } catch (e) {

        }
        callback();
    })

}


//layer 弹框
function layerFn(msg,callback,close){
    layer.open({
        type: 1
        ,offset: 't' //具体配置参考：offset参数项
        ,content: '<div style="padding: 20px 80px;">'+msg+'</div>'
        ,btn: '确定'
        ,btnAlign: 'c' //按钮居中
        ,shade: 0 //不显示遮罩
        ,yes: function(){

            callback!=""&&callback!=undefined?callback():"";
            layer.closeAll();
        }
    });
    $(".layui-layer").css({
        "z-index":"999999999999999999999999999999999999",
        "border":"1px solid #ccc"
    })
    $("#loading").css({
        display:"none"
    });
    callback!=""&&callback!=undefined?"":$(".layui-layer-close1").css({"display":"none"})
    /*$(document).on("click",".layui-layer-close1",function(){
        close!=""&&close!=undefined?"": callback!=""&&callback!=undefined?callback():"";
    })*/

}
function layerFn1(msg,callback,close){
    layer.open({
        type: 1
        ,offset: 't' //具体配置参考：offset参数项
        ,content: '<div style="padding: 20px 80px;">'+msg+'</div>'
        ,btn: '确定'
        ,btnAlign: 'c' //按钮居中
        ,shade: 0.6 //遮罩层颜色为黑色，透明度0。6
        ,yes: function(){

            callback!=""&&callback!=undefined?callback():"";
            layer.closeAll();
        }
    });
    $(".layui-layer").css({
        "z-index":"999999999999999999999999999999999999",
        "border":"1px solid #ccc"
    })
    $(".layui-layer-close1").css({"display":"none"});
    callback!=""&&callback!=undefined?"":$(".layui-layer-close1").css({"display":"none"})
    /*$(document).on("click",".layui-layer-close1",function(){
        close!=""&&close!=undefined?"": callback!=""&&callback!=undefined?callback():"";
    })*/

}
function layerFnBtnTwo(msg,callback,cancel){
    layer.open({
        type: 1
        ,offset: 't' //具体配置参考：offset参数项
        ,content: '<div style="padding: 20px 80px;">'+msg+'</div>'
        ,btn: ['确定',"取消"]
        ,btnAlign: 'c' //按钮居中
        ,shade: 0 //不显示遮罩
        ,yes: function(){
            $("#loading").css({
                display:"none"
            });
            callback!=""&&callback!=undefined?callback():"";
            layer.closeAll();
        }
    });
    $(".layui-layer-btn1").click(function(){
        cancel();
        layer.closeAll();
    })
    $(".layui-layer").css({
        "z-index":"999999999999999999999999999999999999"
    })

}

function trims(data){
    for(var i=0;i<data.datalist.length;i++){
        for(var v in data.datalist[i]){
            data.datalist[i][v]= $.trim(data.datalist[i][v])
            //data.datalist[i][v]= data.datalist[i][v].replace(/\s+/g,""); //$.trim(data.datalist[i][v])
        }
    }
    return data;
}

function compareUp(data,propertyName) { // 升序排序
    if ((typeof data[0][propertyName]) != "number") { // 属性值为非数字
        return function(object1, object2) {
            var value1 = object1[propertyName];
            var value2 = object2[propertyName];
            return value1.localeCompare(value2);
        }
    }
    else {
        return function(object1, object2) { // 属性值为数字
            var value1 = object1[propertyName];
            var value2 = object2[propertyName];
            return value1 - value2;
        }
    }
}

function compareDown(data,propertyName) { // 降序排序
    if ((typeof data[0][propertyName]) != "number") { // 属性值为非数字
        return function(object1, object2) {
            var value1 = object1[propertyName];
            var value2 = object2[propertyName];
            return value2.localeCompare(value1);
        }
    } else {
        return function(object1, object2) { // 属性值为数字
            var value1 = object1[propertyName];
            var value2 = object2[propertyName];
            return value2 - value1;
        }
    }
};

//indexof 兼容ie8
function getIndexof(textsArr,value){
    var index;
    if(!textsArr.indexOf){
        textsArr.indexOf = function(elt /*, from*/){
            var len = this.length >>> 0;
            var from = Number(arguments[1]) || 0;
            from = (from < 0)
                ? Math.ceil(from)
                : Math.floor(from);
            if (from < 0)
                from += len;
            for (; from < len; from++)
            {
                if (from in this &&
                    this[from] === elt)
                    return from;
            }
            return -1;
        };
        index=textsArr.indexOf(value);
    }else{
        index= textsArr.indexOf(value);
    }
    return index;
}

function renderForm(str,m,param,filter,formCallback,selected){//下拉值数组；m对应的下拉框；filter：class/id;回调函数；selected固化显示
    layui.use('form', function(){
        var form = layui.form;//高版本建议把括号去掉，有的低版本，需要加()
        form.render();
        var option="";
        var selt=selected!=undefined&&selected!=""?true:false;
        if(param!=""&&param!=undefined){
            if(str.length>0){

                    for(var i=0;i<str.length;i++){
                        if(selt&&selected==str[i].showName){
                            //option+='<option value="" selected>'+str[i]+'</option>'
                            option+='<option selected value="'+str[i].researchName+'">'+str[i].showName+'</option>';
                        }else{
                            option+='<option value="'+str[i].researchName+'">'+str[i].showName+'</option>';
                        }

                        if(str[i].secondList!=undefined&&str[i].secondList.length>0){
                            for(var v =0;v<str[i].secondList.length;v++){
                                option+='<option style="padding-left:10px;" value="'+str[i].secondList[v].researchName+'">'+"&nbsp&nbsp&nbsp&nbsp"+str[i].secondList[v].showName+'</option>';
                            }
                        }
                    }


            }else{
                //option+='<option value="">暂无数据</option>'
            }
        }else{
            if(str.length>0){
                for(var i=0;i<str.length;i++){
                    if(selt&&selected==str[i]){
                        option+='<option value="" selected>'+str[i]+'</option>'
                    }else{
                        option+='<option value="" >'+str[i]+'</option>'
                    }

                }
            }else{
                /*option+='<option value="">暂无数据</option>'*/
            }
        }
        $(".select"+m).append(option);
        form.on("select("+filter+")", function(data){
            var classType=data.value;
            //console.log(classType);
            if(formCallback!=undefined&&formCallback!=""){
                formCallback(classType);
            }

        });
        form.render();
    });
}

function deleteTips(mesg,sureCallback,cancelCallback){
    layer.confirm(mesg, {
        btn: ['确定','取消'] //按钮
    }, function(){
        sureCallback();
        //cancel();
        var index=layer.confirm;
        layer.close(layer.index);
       // layer.msg('的确很重要', {icon: 1});
    }, function(){
        cancelCallback?cancelCallback():"";
    });
    $(".layui-layer-btn1").click(function(){
        var index=layer.confirm;
        layer.close(layer.index);
    })
    $(".layui-layer").css({
        "z-index":"999999999999999999999999999999999999"
    })
}


//模糊匹配
/**
 * 使用test方法实现模糊查询
 * @param  {Array}  list     原数组
 * @param  {String} keyWord  查询的关键词
 * @return {Array}  arr      查询的结果
 */
function searchData (keyWord, list,param) {
    var len = list.length;
    var arr = [];
    var reg = new RegExp(keyWord);
    if(param!=undefined&&param!=""){
        for(var i=0;i<len;i++){
            //如果字符串中不包含目标字符会返回-1
            //if(list[i][param].match(reg)){
            if(getIndexof(list[i][param],keyWord)>(-1)){
                arr.push(list[i]);
            }
        }
    }else{
        for(var i=0;i<len;i++){
            //如果字符串中不包含目标字符会返回-1
            if(getIndexof(list[i],keyWord)>(-1)){
                arr.push(list[i]);
            }
        }
    }

    return arr;
}
